<template>
  <div>
    <div v-if="!hasRobot">
      <div class="qrcodeStyle">
        <img :src="codeImg" style="width:150px;height:150px;" />
        <div class="qrcodeStyle__tip">
          请商家使用微信扫描上方二维码，并点击确认登录，完成机器人创建
        </div>
      </div>
      <div class="tipContent">重要提醒:</div>
      <div class="tipContent__detail">
        1.为保证服务稳定，建议您优先使用微信小号扫码完成机器人创建！
      </div>
      <div class="tipContent__detail">
        2.若无微信小号，可使用常用微信账号扫描完成机器人创建，此时常用账号会变成机器人，且不能登录网页版和PC版微信，否则会使机器人服务掉线
      </div>
    </div>
    <div v-else>
      <div class="robotList">
        <div class="robotList__top">
          <div class="robotList__top--left">
            <div style="width:60px;height:60px;">
              <img
                src="https://medusa-small-file-1253272780.cos.ap-shanghai.myqcloud.com/gruul/20200610/8e91c8f360d448448fb1bec79ea860b9.jpg"
                style="width:60px;height:60px;"
              />
            </div>
            <div class="leftMsg">
              <div class="leftMsg__title">机器人: 微信昵称</div>
              <div class="leftMsg__title">状态: 在线</div>
            </div>
          </div>
          <div class="robotList__top--right">
            <div class="deal" @click="quitLoad">退出登录</div>
            <div @click="dealLog = true">删除机器人</div>
            <el-dialog :visible.sync="dealLog" width="300px">
              <div class="dealBox">
                <img
                  src="https://medusa-small-file-1253272780.cos.ap-shanghai.myqcloud.com/gruul/20200610/8e91c8f360d448448fb1bec79ea860b9.jpg"
                  style="width:180px;height:180px;"
                />
              </div>
            </el-dialog>
          </div>
        </div>
        <!-- <div class="leader">
          <div class="leader__left">
            <div class="leader__left--addBtn" @click="addLeader">添加团长</div>
            <div class="leader__left--tip">
              （注：请先联系团长将机器人微信添加至所需接龙的群中并在群内发送任意一条消息）
            </div>
          </div>
          <div>
            <el-input placeholder="输入关键字" style="width: 150px;">
              <el-button slot="append" icon="el-icon-search"></el-button>
            </el-input>
          </div>
        </div> -->
        <!-- <el-dialog
          :visible.sync="addShow"
          width="650px"
          :close-on-click-modal="false"
          :show-close="false"
        >
          <div slot="title" class="diaTitle">添加团长</div>
          <LeaderAdd></LeaderAdd>
          <div class="pageButtom">
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="cancel">保存</el-button>
          </div>
        </el-dialog> -->
        <!-- <div style="margin-top: 10px;">
          <RobotList></RobotList>
        </div> -->
      </div>
      <PageManage
        :pageSize="pageSize"
        :pageNum="pageNum"
        :total="total"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
      ></PageManage>
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
import RobotList from "./RobotList.vue";
import PageManage from "@/components/PageManage.vue";
import { robotLogin } from "@/api/chainActivity/chainActivity";

@Component({
  components: {
    RobotList,
    PageManage,
  },
})
export default class RobotManage extends Vue {
  pageSize = 10;

  pageNum = 1;

  total = 0;

  /** 手动添加团长弹框 */
  addShow = false;

  /** 删除弹窗 */
  dealLog = false;

  codeImg = "";

  /** 是否已有机器人 */
  hasRobot = false;

  mounted() {
    this.login();
  }

  /**
   * 登录机器人
   */
  login() {
    robotLogin({}).then(res => {
      this.codeImg = res.data;
    });
  }

  /**
   * 退出登录
   */
  quitLoad() {
    this.$confirm("退出登录后机器人将掉线，无法为微信群工作?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        this.$message({
          type: "success",
          message: "删除成功!",
        });
      })
      .catch(() => {
        this.$message({
          type: "info",
          message: "已取消删除",
        });
      });
  }

  /**
   * 手动添加团长
   */
  addLeader() {
    this.addShow = true;
  }

  /** 取消操作 */
  cancel() {
    this.addShow = false;
  }

  /**
   * @method handleSizeChange
   * @description 每页 条
   */
  handleSizeChange(val) {
    console.log("val", val);
  }

  /**
   * @method handleCurrentChange
   * @description 当前页
   */
  handleCurrentChange(val) {
    console.log("val", val);
  }
}
</script>

<style lang="scss" scoped>
.qrcodeStyle {
  height: 160px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 60px;

  &__tip {
    width: 100%;
    margin-top: 20px;
    display: flex;
    justify-content: center;
  }
}

.tipContent {
  margin-top: 100px;
  color: #fe4e63;
  padding-left: 40px;

  &__detail {
    margin-top: 10px;
    padding-left: 40px;
  }
}

@include b(robotList) {
  width: 100;
  background-color: #f9f9f9;
  padding: 10px;
  @include e(top) {
    padding: 20px;
    width: 100%;
    background-color: white;
    display: flex;
    justify-content: space-between;
    @include m(left) {
      display: flex;
      .leftMsg {
        display: flex;
        align-content: space-between;
        width: 250px;
        flex-wrap: wrap;
        margin-left: 10px;
        padding: 5px 0px;

        &__title {
          width: 150px;
          color: #333333;
        }
      }
    }
    @include m(right) {
      display: flex;
      color: #006eff;
      cursor: pointer;
      align-items: flex-end;
      .deal::after {
        content: "|";
        margin: 0px 10px;
      }
    }
  }
}

@include b(leader) {
  width: 100%;
  height: 60px;
  display: flex;
  justify-content: space-between;
  padding: 10px;
  background-color: white;
  align-items: center;
  margin-top: 10px;
  @include e(left) {
    display: flex;
    align-items: center;
    @include m(addBtn) {
      width: 90px;
      height: 40px;
      color: #2d8cf0;
      border: 1px solid #2d8cf0;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 12px;
      border-radius: 5px;
      cursor: pointer;
    }
    @include m(tip) {
      color: #c8c8c8;
      margin-left: 5px;
    }
  }
}

.dealBox {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.diaTitle {
  font-weight: bold;
  font-size: 15px;
}

.pageButtom {
  display: flex;
  width: 100%;
  justify-content: flex-end;
  margin-top: 20px;
}
</style>
